﻿using System;
using System.IO;
using System.Windows.Media.Imaging;
using GalaSoft.MvvmLight.Messaging;
using IssueVision.Data.Web;

namespace IssueVision.Common
{
    /// <summary>
    /// class that defines all messages used in this application
    /// </summary>
    public static class AppMessages
    {
        enum MessageTypes
        {
            // MainPage View messages
            ChangeScreen,
            ChangeScreenNoAnimation,
            RaiseError,
            PleaseConfirm,
            StatusUpdate,
            // IssueEditorViewModel messages
            EditIssue,
            // IssueEditor View message
            ReadOnlyIssue,
            OpenFile,
            SaveFile,
            // Reports View message
            GetCharts
        }

        public static class ChangeScreenMessage
        {
            public static void Send(string screenName)
            {
                Messenger.Default.Send(screenName, MessageTypes.ChangeScreen);
            }

            public static void Register(object recipient, Action<string> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.ChangeScreen, action);
            }
        }

        public static class ChangeScreenNoAnimationMessage
        {
            public static void Send(string screenName)
            {
                Messenger.Default.Send(screenName, MessageTypes.ChangeScreenNoAnimation);
            }

            public static void Register(object recipient, Action<string> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.ChangeScreenNoAnimation, action);
            }
        }

        public static class RaiseErrorMessage
        {
            public static void Send(Exception ex)
            {
                Messenger.Default.Send(ex, MessageTypes.RaiseError);
            }

            public static void Register(object recipient, Action<Exception> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.RaiseError, action);
            }
        }

        public static class PleaseConfirmMessage
        {
            public static void Send(DialogMessage dialogMessage)
            {
                Messenger.Default.Send(dialogMessage, MessageTypes.PleaseConfirm);
            }

            public static void Register(object recipient, Action<DialogMessage> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.PleaseConfirm, action);
            }
        }

        public static class StatusUpdateMessage
        {
            public static void Send(DialogMessage dialogMessage)
            {
                Messenger.Default.Send(dialogMessage, MessageTypes.StatusUpdate);
            }

            public static void Register(object recipient, Action<DialogMessage> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.StatusUpdate, action);
            }
        }

        public static class EditIssueMessage
        {
            public static void Send(Issue issue)
            {
                Messenger.Default.Send(issue, MessageTypes.EditIssue);
            }

            public static void Register(object recipient, Action<Issue> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.EditIssue, action);
            }
        }

        public static class ReadOnlyIssueMessage
        {
            public static void Send(Boolean readOnly)
            {
                Messenger.Default.Send(readOnly, MessageTypes.ReadOnlyIssue);
            }

            public static void Register(object recipient, Action<Boolean> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.ReadOnlyIssue, action);
            }
        }

        public static class OpenFileMessage
        {
            public static void Send(NotificationMessageAction<FileInfo> message)
            {
                Messenger.Default.Send(message, MessageTypes.OpenFile);
            }
            public static void Register(object recipient, Action<NotificationMessageAction<FileInfo>> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.OpenFile, action);
            }
        }

        public static class SaveFileMessage
        {
            public static void Send(Data.Web.File saveFile)
            {
                Messenger.Default.Send(saveFile, MessageTypes.SaveFile);
            }

            public static void Register(object recipient, Action<Data.Web.File> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.SaveFile, action);
            }
        }

        public static class GetChartsMessage
        {
            public static void Send(NotificationMessageAction<WriteableBitmap> message)
            {
                Messenger.Default.Send(message, MessageTypes.GetCharts);
            }
            public static void Register(object recipient, Action<NotificationMessageAction<WriteableBitmap>> action)
            {
                Messenger.Default.Register(recipient, MessageTypes.GetCharts, action);
            }
        }
    }
}